﻿#define DEBUG_AGENT
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.IO;
using Microsoft.Phone.Shell;
using System.Linq;
using OnlineVideos.Library;
using Common.Library;
using Microsoft.Phone.Info;
using Windows.Storage;
using System.Threading.Tasks;
using Windows.ApplicationModel;

namespace OnlineVideos
{
    public class DataHelper
    {
        public void CopyDefaultImage()
        {
            try
            {
                string gg = ResourceHelper.ProjectName;
                if (ResourceHelper.AppName == Apps.Indian_Cinema.ToString() || ResourceHelper.AppName == Apps.Indian_Cinema_Pro.ToString() || ResourceHelper.AppName == Apps.Story_Time.ToString() || ResourceHelper.AppName == Apps.Online_Education.ToString() || ResourceHelper.AppName == Apps.Kids_TV_Shows.ToString() || ResourceHelper.AppName == Apps.Kids_TV_Pro.ToString() || ResourceHelper.AppName == Apps.Kids_TV.ToString() || ResourceHelper.AppName == Apps.Animation_Planet.ToString() || ResourceHelper.AppName == Apps.Bollywood_Movies.ToString() || ResourceHelper.AppName == Apps.Bollywood_Music.ToString() || ResourceHelper.AppName == Apps.World_Dance.ToString() || ResourceHelper.AppName == Apps.Yoga_and_Health.ToString().Replace("and", "&") || ResourceHelper.AppName == Apps.Fitness_Programs.ToString() || ResourceHelper.AppName == Apps.Recipe_Shows.ToString() || ResourceHelper.AppName == Apps.Vedic_Library.ToString() || ResourceHelper.AppName == Apps.DrivingTest.ToString() || ResourceHelper.AppName == Apps.Video_Games.ToString() || ResourceHelper.AppName == Apps.Cricket_Videos.ToString())
                {

                        StorageFile databaseFile = Task.Run(async () => await Package.Current.InstalledLocation.GetFileAsync("Images\\Default.jpg")).Result;
                        StorageFolder sf = ApplicationData.Current.LocalFolder;
                        StorageFile sf1 = Task.Run(async () => await sf.CreateFileAsync("Images\\Default.jpg", CreationCollisionOption.OpenIfExists)).Result;
                        Task.Run(async () => await databaseFile.CopyAndReplaceAsync(sf1));
                  
                }
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in CopyDefaultImage Method In DataHelper.cs file", ex);
            }
        }
        public void MoveReferenceDatabase()
        {

            try
            {

                StorageFile databaseFile1 = Task.Run(async () => await Package.Current.InstalledLocation.GetFileAsync("Claps.mp3")).Result;
                StorageFolder sf2 = ApplicationData.Current.LocalFolder;
                StorageFile sf3 = Task.Run(async () => await sf2.CreateFileAsync("Claps.mp3", CreationCollisionOption.OpenIfExists)).Result;
                Task.Run(async () => await databaseFile1.CopyAndReplaceAsync(sf3));
            }
            catch (Exception ex)
            {
                
               
            }
        }
      
        public void CopyDatabase()
        {
            try
            {
                StorageFile databaseFile = Task.Run(async () => await Package.Current.InstalledLocation.GetFileAsync("OnlineMoviesDb.sqlite")).Result;
                StorageFolder sf = ApplicationData.Current.LocalFolder;
                StorageFile sf1 = Task.Run(async () => await sf.CreateFileAsync("OnlineMoviesDb.sqlite", CreationCollisionOption.OpenIfExists)).Result;
                Task.Run(async () => await databaseFile.CopyAndReplaceAsync(sf1));
            }
            catch (Exception ex)
            {
                Exceptions.SaveOrSendExceptions("Exception in CopyDatabase Method In DataHelper.cs file", ex);
            }

        }

        public void Deletexml()
        {
            Storage.DeleteFile(ResourceHelper.ProjectName + "/Videos.xml");
            Storage.DeleteFile(ResourceHelper.ProjectName + "/Description.xml");
            Storage.DeleteFile(ResourceHelper.ProjectName + "/PersonProfile.xml");
            Storage.DeleteFile(ResourceHelper.ProjectName + "/TempCast.xml");
            Storage.DeleteFile(ResourceHelper.ProjectName + "/TempRuns.xml");
            Storage.DeleteFile(ResourceHelper.ProjectName + "/Roles.xml");
            Storage.DeleteFile(ResourceHelper.ProjectName + "/Songs.xml");
            Storage.DeleteFile(ResourceHelper.ProjectName + "/Countries.xml");
            Storage.DeleteFile(ResourceHelper.ProjectName + "/Result.xml");
            Storage.DeleteFile(ResourceHelper.ProjectName + "/Catageory.xml");
        }
       

        public  void IsLowMemDevice()
        {
            try
            {

                // Check the working set limit and set the IsLowMemDevice flag accordingly.
                Int64 result = (Int64)DeviceExtendedProperties.GetValue("ApplicationWorkingSetLimit");
                if (result < 94371840L)
                Storage.IsLowMemDevice = true;
                else
                  Storage.IsLowMemDevice= false;
            }
            catch (ArgumentOutOfRangeException)
            {
                // Windows Phone OS update not installed, which indicates a 512-MB device. 
                Storage.IsLowMemDevice= false;
            }
        }
    }
}

